//------------------------------------------------------------------------------
#include <QtGui>
#include <QComboBox>
#include "CComboDelegate.h"
//------------------------------------------------------------------------------
CComboDelegate::CComboDelegate(const QStringList &items, QObject *parent) : QItemDelegate(parent)
{
	_items=items;
}
//------------------------------------------------------------------------------
QWidget * CComboDelegate::createEditor(	QWidget *parent, const QStyleOptionViewItem &option,
											const QModelIndex &index) const
{
	QComboBox *editor=new QComboBox(parent);
	editor->addItems(_items);
	
	return editor;
}
//------------------------------------------------------------------------------
void CComboDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
	QString value=index.model()->data(index, Qt::EditRole).toString();
	
	QComboBox *comboBox=static_cast<QComboBox *>(editor);
	comboBox->setCurrentIndex(comboBox->findText(value));
}
//------------------------------------------------------------------------------
void CComboDelegate::setModelData(	QWidget *editor, QAbstractItemModel *model,
										const QModelIndex &index) const
{
	QComboBox *comboBox=static_cast<QComboBox *>(editor);
	QString value=comboBox->currentText();
	model->setData(index, value, Qt::EditRole);
}
//------------------------------------------------------------------------------
void CComboDelegate::updateEditorGeometry(	QWidget *editor,
												const QStyleOptionViewItem &option,
	   											const QModelIndex &index) const
{
	editor->setGeometry(option.rect);
}
//------------------------------------------------------------------------------